package com.cxx.utils;

import com.cxx.properties.JwtProperties;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
public class JwtUtils {
    private String signKey="cxx2002104";
    private long expire=7200000;
    public  String generateJwt(Map<String,Object> claims){
        String jwt= Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,signKey)
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis()+expire))
                .compact();
        return jwt;
    }
    public  Claims parseJwt(String Jwt){
        Claims c= Jwts.parser().setSigningKey(signKey).parseClaimsJws(Jwt).getBody();
        return c;
    }

}
